﻿using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Security;
using TripRemoteObject;


namespace PaymentServer
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                TcpChannel channel = new TcpChannel(Properties.Settings.Default.RemotingPort);
                ChannelServices.RegisterChannel(channel, false);
                // Expose an object for remote calls.
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(TripChanges), Properties.Settings.Default.RemoteObjectURI, WellKnownObjectMode.Singleton);
                MessageQueueMgr.Instance.StartReceive();
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine("Error:" + ex.Message);
            }
            catch(RemotingException ex)
            {
                Console.WriteLine("Channel already registered.");
            }
            catch(SecurityException ex)
            {
                Console.WriteLine("Security error:" + ex.Message);                
            }

            Console.WriteLine("Press ENTER to exit the server.");
            Console.ReadLine();
            Console.WriteLine("The server is exiting.");
        }
    }
}
